package org.herui.campus.service.properties;

import lombok.Data;
import org.herui.campus.properties.PropertyValueInfo;
import org.herui.campus.service.cache.config.CacheKeys;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * @author zzb
 * @version 1.0
 * @date 2024/2/1 14:51
 */
@ConfigurationProperties(prefix = "org.herui.campus.makewin")
@Data
public class MakeWinProperties extends BaseProperties {

    private Map<String, List<PropertyValueInfo>> map = new HashMap<>();

    public void init() {
        List<PropertyValueInfo> propertyValueInfos = new LinkedList<>();

        propertyValueInfos = new LinkedList<>();
        propertyValueInfos.add(new PropertyValueInfo("productKey", "产品key", "Nc2mzSAchhQ", true));
        propertyValueInfos.add(new PropertyValueInfo("deviceName", "设备标识", "make_win_server", true));
        propertyValueInfos.add(new PropertyValueInfo("deviceSecret", "设备秘钥", "PK7UQV27IZLR2NVcOrKtFJfeb19MHBCx", true));
        propertyValueInfos.add(new PropertyValueInfo("mqttAddr", "mqtt服务器地址", "localhost", true));
        propertyValueInfos.add(new PropertyValueInfo("mqttPort", "mqtt服务器端口", "1886", true));
        propertyValueInfos.add(new PropertyValueInfo("mqttGroup", "mqtt群组标识", "iotDeviceGroup", false));
        map.put(CacheKeys.MAKE_WIN_MQTT_PARAM_KEY, propertyValueInfos);

        super.init();
    }

    public Map<String, List<PropertyValueInfo>> getMap() {
        return map;
    }

    @Override
    public String getTitle() {
        return "设备服务参数";
    }

    public String getProductKey() {
        PropertyValueInfo propertyValueInfo = get(CacheKeys.MAKE_WIN_MQTT_PARAM_KEY, "productKey");
        return propertyValueInfo.getValue();
    }

    public String getDeviceName() {
        PropertyValueInfo propertyValueInfo = get(CacheKeys.MAKE_WIN_MQTT_PARAM_KEY, "deviceName");
        return propertyValueInfo.getValue();
    }

    public String getDeviceSecret() {
        PropertyValueInfo propertyValueInfo = get(CacheKeys.MAKE_WIN_MQTT_PARAM_KEY, "deviceSecret");
        return propertyValueInfo.getValue();
    }

    public String getMqttAddr() {
        PropertyValueInfo propertyValueInfo = get(CacheKeys.MAKE_WIN_MQTT_PARAM_KEY, "mqttAddr");
        return propertyValueInfo.getValue();
    }

    public int getMqttPort() {
        PropertyValueInfo propertyValueInfo = get(CacheKeys.MAKE_WIN_MQTT_PARAM_KEY, "mqttPort");
        String value = propertyValueInfo.getValue();
        return Integer.valueOf(value);
    }

    public String getMqttGroup() {
        PropertyValueInfo propertyValueInfo = get(CacheKeys.MAKE_WIN_MQTT_PARAM_KEY, "mqttGroup");
        return propertyValueInfo.getValue();
    }
}
